package ucm.controller;

import air_cp5620.util.ProcessPassword;
import java.security.NoSuchAlgorithmException;
import javax.swing.JOptionPane;
import ucm.module.UC_RegM;

public class UC_RegC {
    private String userName = null;
    private String passWord = null;
    private String rePassWord = null;
    private String roleid = null;



    public UC_RegC(String UserName, String PassWord, String RePassWord,String RoleId) throws NoSuchAlgorithmException {
        this.userName = UserName;
        this.passWord = ProcessPassword.encrypt(PassWord);
        this.rePassWord = ProcessPassword.encrypt(RePassWord);
        if (RoleId.equals("Ordinary Account")) {
            this.roleid = "100001";
        }
        else if (RoleId.equals("Account Manager")) {
            this.roleid = "100002";
        }
        else {
            this.roleid = "100003";
        }
    }


    
    public boolean run()
    {
        if (userName.equals("") || passWord.equals("") || rePassWord.equals("") || roleid.equals(""))
        {
            JOptionPane.showMessageDialog(null, "Users fill out registration information is incomplete, please fill out the full!");
            return false;
        }
        if (!passWord.equals(rePassWord))
        {
            JOptionPane.showMessageDialog(null, "User registration information is not the same as the password twice!");
            return false;
        }
        UC_RegM uc_regm = new UC_RegM(userName, passWord,roleid);
        return uc_regm.regisger();
    }
}
